package com.samuel.igoodman.web.article;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import com.samuel.igoodman.dao.article.ArticleDao;
import com.samuel.igoodman.entity.Page;
import com.samuel.igoodman.entity.account.Userinfo;
import com.samuel.igoodman.entity.article.Article;
import com.samuel.igoodman.web.base.BaseAction;

@SuppressWarnings("serial")
public class ArticleAction extends BaseAction {

	
	private Article article;
	
	//读取保存
	public String write(){
		if("save".equals(op)){
			Userinfo userinfo = getCurrUserinfo();
			if(null!=userinfo){
				article.setUserinfoId(userinfo.getId());
				article.setUsername(userinfo.getUsername());
			}
			article.setSaveDate(new Timestamp(new Date().getTime()));
			article.setDate(new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
			long id = article.Save();
			article.setId(id);
			return DETAIL;
		}
		return SUCCESS;
	}
	
	//文章详情
	public String detail(){
		article = article.Get(article.getId());
		return SUCCESS;
	}
	
	//列表
	public String list(){
		List<Article> articleList =  ArticleDao.getArticleByDate(new SimpleDateFormat("yyyy-MM-dd").format(new Date()), 1, Page.PAGE_SIZE);
		setRequestAtt("articleList", articleList);
		return SUCCESS;
	}

	public Article getArticle() {
		return article;
	}

	public void setArticle(Article article) {
		this.article = article;
	}
	
	
	
}
